import React, { Component } from 'react'

export default class App extends Component {
    state = {
        count: 1
    }
    render() {
        console.log('render run!')
        let { count } = this.state
        return (
            <>
                <div>count: {count}</div>
                <button onClick={() => {
                    console.log(1111)
                    // setState是异步的，使用方式一：参数是一个对象
                    this.setState({
                        count: count + 1
                    })
                    this.setState({
                        count: count + 1
                    })
                    this.setState({
                        count: count + 1
                    })
                    console.log(2222)
                }}>count+3</button>

                <button onClick={()=>{
                    console.log(111)
                    // setState 参数是一个回调函数，回调函数的参数，是最新的状态数据
                    this.setState((state)=>{

                        console.log(333, state);
                        return {count: state.count + 1}
                    })
                    this.setState((state)=>{

                        console.log(333, state);
                        return {count: state.count + 1}
                    })
                    this.setState((state)=>{

                        console.log(333, state);
                        return {count: state.count + 1}
                    })
                    
                    console.log(222)
                }}>参数是函数</button>
            </>
        )
    }
}
